﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Reflection;

namespace MM.Common
{
    public class ComHelper
    {
        public static string GetWebResponse(string strURL, string strUserAgent, string strContentType)
        {
            string strResult = string.Empty;
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strURL);
            myReq.Method = "GET";
            myReq.UserAgent = strUserAgent;
            myReq.ContentType = strContentType;
            Stream outStream = myReq.GetResponse().GetResponseStream();
            StreamReader readStream = new StreamReader(outStream);
            Char[] read = new Char[256];
            int count = readStream.Read(read, 0, 256);
            while (count > 0)
            {
                strResult += new String(read, 0, count);
                count = readStream.Read(read, 0, 256);
            }
            outStream.Close();
            return strResult;
        }
        /// <summary>
        /// 获取post过来的数据
        /// </summary>
        /// <param name="objHttpRequest"></param>
        /// <returns></returns>
        public static string GetInputStream(System.Web.HttpRequest objHttpRequest)
        {
            string strResult = string.Empty;
            System.IO.Stream objStream = objHttpRequest.InputStream;
            if (objStream != null)
            {
                StreamReader readStream = new StreamReader(objStream);
                Char[] read = new Char[256];
                int count = readStream.Read(read, 0, 256);
                while (count > 0)
                {
                    strResult += new String(read, 0, count);
                    count = readStream.Read(read, 0, 256);
                }
                objStream.Close();
            }
            return strResult;
        }
        /// <summary>
        /// 分转换成元
        /// </summary>
        /// <param name="Fen"></param>
        /// <returns></returns>
        public static decimal GetYuan(int Fen)
        {
            decimal delResult = 0;
            if (Fen > 0)
            {
                delResult = Fen.ToDecimal() / 100;
            }
            return delResult;
        }
    }
}
